Skip to content

[26.04_linux-nvidia] NVIDIA: SAUCE: watchdog: sbsa_gwdt: stop the watchdog across the whole system-sleep transition - #568

Open
dcemin-nv wants to merge 1 commit into
NVIDIA:26.04_linux-nvidiafrom
dcemin-nv:wdog-pm-fix-26.04
Open

[26.04_linux-nvidia] NVIDIA: SAUCE: watchdog: sbsa_gwdt: stop the watchdog across the whole system-sleep transition#568
dcemin-nv wants to merge 1 commit into
NVIDIA:26.04_linux-nvidiafrom
dcemin-nv:wdog-pm-fix-26.04

Conversation

@dcemin-nv

@dcemin-nv dcemin-nv commented Sep 3, 2026

Copy link
Copy Markdown

BugLink: https://bugs.launchpad.net/ubuntu/+source/linux-nvidia/+bug/2166302

Fix for a watchdog initiated system reset during suspend entry, found and root caused on the N1x laptop program.

The driver stops a running watchdog only in its device suspend callback, which leaves it armed with nobody refreshing it through userspace freeze, kernel thread freeze, and every device suspend callback that runs earlier (same window at the tail of resume). With the watchdog running from boot and a 10 second timeout, any slow device suspend resets the system mid entry. On N1x this fired on about 7 percent of suspend attempts in randomized stress runs (9 resets in 124 suspends); two elimination runs confirm the mechanism (0 resets in 118 with the watchdog off, 0 in 198 with this fix and the watchdog force enabled, where the baseline rate predicts about 14).

v3: the notifier owns the transition, stopping at PREPARE and restarting at PM_POST, with the driver state kept under a lock shared with the watchdog ops so a userspace stop or magic close after thaw cannot race the restart, and a start requested during the transition is deferred to PM_POST_*. The notifier is registered before anything can arm the watchdog and its failure fails the probe. A suspend-only device callback remains as the final guard for a probe that overlapped the PREPARE event; it has no resume counterpart. The commit carries Fixes: 57d2caa ("Watchdog: introduce ARM SBSA watchdog driver").

Validation: the 198 suspend elimination matrix and the 200 cycle confirmation run were performed on v1 (notifier plus dev_pm_ops). v2 is compile verified on both branches; the change relative to v1 only removes the redundant device callbacks, so the v1 soak result is claimed for v2. Shipping in the N1x FastOS kernel.

Notes for review:

  • Applies independently of the early_enable parameter (PR 557/558, now applied via Launchpad), but it is the companion fix: the armed during entry window exists for any system running the SBSA watchdog from boot, so this is also upstream relevant and is being prepared for the linux-watchdog list.
  • Happy to file or reference a Launchpad bug if that is the preferred tracking here, as was done for early_enable.

@nirmoy nirmoy added the help wanted Extra attention is needed label Sep 3, 2026
@nirmoy

nirmoy commented Sep 3, 2026

Copy link
Copy Markdown
Collaborator

BaseOS Kernel Review

Warning

⚠️ Review needs attention

The SBSA watchdog can still arm during early suspend if it was initially stopped, risking a reset before device suspend callbacks complete. A distinct transition-in-progress flag is needed.

Findings: Critical 0 · High 1 · Medium 0 · Low 0

🔍 Review artifacts

📦 Kernel deb builds — 🟢 2/2 passed

Note

Build reports and debs are retained for 10 days after the PR closes.

Review metadata
  • Reviewed head: 40aebd1a8a1f
  • Overall status: attention needed
  • Architectures: 2/2 successful

This comment is maintained by BaseOS Reviewer and updated when the GitHub watcher publishes a newer review.

@github-actions

github-actions Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

PR Validation Report

Patchscan ✅ No Missing Fixes

All cherry-picked commits checked — no missing upstream fixes found.

PR Lint ✅ All checks passed

Details
Checking 1 commits...

Cherry-pick digest:
┌──────────────┬──────────────────────────────────────────────────────────────────┬────────────┬─────────┬───────────────────────────┐
│ Local        │ Referenced upstream / Patch subject                              │ Patch-ID   │ Subject │ SoB chain                 │
├──────────────┼──────────────────────────────────────────────────────────────────┼────────────┼─────────┼───────────────────────────┤
│ 40aebd1a8a1f │ [SAUCE] watchdog: sbsa_gwdt: stop the watchdog across the whole  │ N/A        │ N/A     │ dcemin                    │
└──────────────┴──────────────────────────────────────────────────────────────────┴────────────┴─────────┴───────────────────────────┘

Lint: all checks passed.

@nirmoy

nirmoy commented Sep 3, 2026

Copy link
Copy Markdown
Collaborator

@dcemin-nv I created the Launchpad bug for this change:
https://bugs.launchpad.net/ubuntu/+source/linux-nvidia/+bug/2166302

Could you please add this link to the PR description?

Also we need below information to track these patches:
What are the upstream plans for these?
Are these related to a specific NVbug?

@jamieNguyenNVIDIA

Copy link
Copy Markdown
Collaborator

@dcemin-nv

  • What are the upstream plans for this?
  • Is this related to a specific NVbug?

@dcemin-nv

Copy link
Copy Markdown
Author

Tracking info: internal NVbug 6611666 (watchdog initiated reset during suspend entry on the N1x stress runs). Upstream plan: the patch is prepared against current mainline and is being posted to linux-watchdog (Wim Van Sebroeck, Guenter Roeck cc linux-watchdog@vger.kernel.org); I will add the lore link here once it is archived.

@clsotog

clsotog commented Sep 4, 2026

Copy link
Copy Markdown
Collaborator

This is what I found with Codex:
The watchdog still restarts during device resume, before PM_POST_. The PM notifier stops the hardware in PM_PREPARE and intends to restart it at PM_POST* (drivers/watchdog/sbsa_gwdt.c:304), but the existing device resume callback still calls sbsa_gwdt_start() whenever WDOG_HW_RUNNING is set (drivers/watchdog/sbsa_gwdt.c:463).
Since the notifier calls the driver stop directly, that bit stays set. Normal suspend runs dpm_resume_end() before PM_POST_SUSPEND (kernel/power/suspend.c:536, kernel/power/suspend.c:560), so a slow later resume/thaw path can still reset the system. The device resume path should skip restart when the notifier owns the sleep transition, or track a stopped_by_pm_notifier state and let only PM_POST_* re-arm.

@dcemin-nv

Copy link
Copy Markdown
Author

@clsotog the finding is correct. The PM notifier stops the hardware by calling the driver's stop op directly, so WDOG_HW_RUNNING stays set, and the existing dev_pm_ops resume callback then restarts the watchdog during dpm_resume, before PM_POST_SUSPEND. That leaves the watchdog armed with nobody refreshing it through thaw, a shorter window than the entry side this patch fixes, but the same class of problem.

Fix for v2: with the notifier owning the whole sleep transition, the per device suspend and resume callbacks are redundant, so I will drop SET_SYSTEM_SLEEP_PM_OPS from the driver and let PM_PREPARE and PM_POST be the only stop and start points. I will also rebase the branch onto current 26.04_linux-nvidia, since it currently duplicates three commits that have since landed in the base. The same v2 goes to the linux-watchdog list.

@clsotog

clsotog commented Sep 9, 2026

Copy link
Copy Markdown
Collaborator

Thanks one more little thing at the commit I see this line:
Change-Id: Id280d16321354d78f5dd766e82371bca25a4a2ea
We do not need this line for our commits to Canonical.

@dcemin-nv

Copy link
Copy Markdown
Author

v2 pushed: e28c4a4 (569: 1f857bc). Fixes: 57d2caa trailer added, Change-Id line removed, description updated to the v2 behaviour (no dev_pm_ops, the notifier is the sole stop and start point). On the retest question: the change relative to v1 only removes the redundant device callbacks, so the v1 soak result is claimed for v2.

@clsotog

clsotog commented Sep 10, 2026

Copy link
Copy Markdown
Collaborator

Thanks for the changes. There are comments in PR 569. This is what codex found in my part:

  • P2 drivers/watchdog/sbsa_gwdt.c:322 removes the late device suspend stop, leaving a late-start window. PM_SUSPEND_PREPARE and hibernation prepare run before tasks are frozen, so userspace can still open/start /dev/watchdog after this notifier runs. Since the PR also removes dev_pm_ops, nothing stops that newly armed watchdog before device suspend/system sleep, and it can still reset the system during the transition. Keep a suspend-only device PM stop as a final guard, or otherwise block/re-stop starts while system sleep is in progress.

@jamieNguyenNVIDIA

Copy link
Copy Markdown
Collaborator

Thanks, the Fixes:/Change-Id cleanup and the v2 PR-description clarification are addressed on both paired heads. I found two additional items:

  • The notifier can miss a concurrent probe. PM_SUSPEND_PREPARE runs at kernel/power/suspend.c:381, before dpm_prepare() waits for active probes and blocks new ones at drivers/base/power/main.c:2220-2227. A probe that passed the block check can therefore observe or start a running watchdog and reach notifier registration at drivers/watchdog/sbsa_gwdt.c:454-455 only after the prepare event has passed. Suspend then waits for the probe to finish, but with dev_pm_ops removed there is no remaining callback to stop that watchdog, so it can stay armed through the transition. Please make notifier readiness atomic with probe visibility/system-sleep entry, or retain a safe device-PM fallback that cannot re-arm early on resume.

  • Both permanent commit messages still say that “with this patch applied and the watchdog force-enabled” the 198-suspend run had zero resets. The updated PR descriptions now clarify that the 198/200-cycle runs used v1 and these v2 heads were only compile-tested. Please scope the commit-message validation sentence to the v1-tested revision and state that v2 removes the device callbacks, so the durable history matches the actual validation provenance.

…e system-sleep transition

The driver stops a running watchdog in its own device suspend callback
and restarts it in its resume callback. That leaves the watchdog armed,
with nobody refreshing it, for the entire early part of suspend entry:
userspace freeze, kernel thread freeze, and every device suspend
callback that runs before this device's own. The same window exists at
the tail end of resume.

When the watchdog is running from boot (early_enable=1, previously
force_enable=1 downstream; 10 s default timeout) and any device stalls
its suspend callback past the timeout, the watchdog resets the system
in the middle of suspend entry. On N1x (Yukon) this fired on about 7%
of suspend attempts in a randomized stress run (9 resets in 124
suspends; the serial console shows the board dropping into the boot
ROM mid-entry with the watchdog reset status set in NONRST_REG2). Two
elimination runs confirm the mechanism: the identical stress matrix
with the parameter off produced zero resets in 118 suspends, and with
the first version of this change (notifier plus the original device
callbacks) applied and the watchdog force-enabled, zero resets in 198
suspends across four runs (the baseline rate predicts about 14). The
version here keeps that mechanism, removes the device resume callback
and adds the locking described below; it is compile tested.

Stop the watchdog from a PM notifier at the *_PREPARE events, before
tasks are frozen and device callbacks run, and restart it at the
PM_POST_* events, after everything has resumed. The driver state (armed,
stopped for sleep) lives under a lock shared with the watchdog ops, so a
userspace stop or magic close after thaw cannot race the restart, and a
start requested while the transition is in progress is deferred until
PM_POST_* instead of arming hardware nobody can refresh. The notifier is
registered before anything can arm the watchdog and its failure fails
the probe. A suspend-only device callback remains as the final guard for
a device whose probe overlapped the *_PREPARE event; it has no resume
counterpart, so nothing re-arms the watchdog during device resume,
before PM_POST_SUSPEND.

This is also upstream-relevant as a companion to the early_enable
parameter: the armed-during-entry window exists for any system running
the SBSA watchdog from boot.

Fixes: 57d2caa ("Watchdog: introduce ARM SBSA watchdog driver")
Signed-off-by: David Cemin <dcemin@nvidia.com>
@dcemin-nv

Copy link
Copy Markdown
Author

v3 pushed: 568 = 40aebd1, 569 = 3f6de47, same driver file on both. It addresses the four points raised by Nirmoy (Codex P1/P2), Cristian and Jamie:

  • Restart racing a userspace stop or magic close after thaw (P1). The driver now keeps its own state, hw_armed and pm_stopped, under a spinlock shared by the watchdog ops and the sleep hooks. ops->stop clears both bits and stops the hardware; the PM_POST_* restart runs under the same lock and only if pm_stopped is still set and hw_armed still true, so a stop that landed after thaw wins and nothing re-arms behind the core's back. The stale WDOG_HW_RUNNING check is gone.
  • Start after PREPARE and before task freezing (Cristian, and the second half of P1). ops->start sets hw_armed but, while pm_stopped is set, leaves the hardware stopped; the PM_POST_* hook arms it once everything has resumed. A watchdog opened during the entry window therefore cannot fire during the transition.
  • Concurrent probe (Jamie). A suspend-only device callback remains as the final guard: it runs the same stop as the PREPARE hook, so a device whose probe overlapped the PREPARE event still gets stopped at dpm_suspend. It has no resume counterpart, so nothing re-arms the hardware before PM_POST_SUSPEND; the restart is owned by the notifier, which by then is registered.
  • Notifier registration failure (P2). The notifier is registered first thing in probe, before early_enable can arm anything and before the watchdog device is registered, and its failure now fails the probe with dev_err_probe. Nothing is left armed on that path.

Commit message: the validation sentence is scoped to the first revision (notifier plus the original device callbacks, 198 suspends, zero resets) and states that this revision is compile tested; the Fixes: trailer is unchanged. Both flavours built with W=1 with no warnings, checkpatch strict is clean.

@jamieNguyenNVIDIA

Copy link
Copy Markdown
Collaborator

I agree with the current Boro finding about the remaining pm_stopped/late-start and concurrent-probe race, so I will not duplicate it.

Nit: Both PR descriptions still say “v2 is compile verified” and claim the v1 soak result for v2. These are now substantive v3 heads with new locking and a suspend fallback. Please update the validation paragraph to identify the exact v3 build validation and keep it distinct from the v1 runtime soak.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

help wanted Extra attention is needed pending_review_comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants